﻿Imports System.Data.SqlClient

Public Class QuanDAO
    Public Shared Function GetAllQuanDAO() As DataTable
        ' Dim sqlcn As SqlDataProvider = New SqlDataProvider()
        Dim cn As SqlConnection
        cn = SqlDataProvider.ConnectionData()
        Dim ds As ArrayList = New ArrayList()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "DanhSach_Quan"
        cmd.Connection = cn
        Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
        Dim dt As DataTable = New DataTable()
        da.Fill(dt)
        Return dt


    End Function

    Public Shared Function GetMaQuanDAO() As DataTable
        ' Dim sqlcn As SqlDataProvider = New SqlDataProvider()
        Dim cn As SqlConnection
        cn = SqlDataProvider.ConnectionData()
        Dim ds As ArrayList = New ArrayList()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "DanhSachMa_Quan"
        cmd.Connection = cn
        Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
        Dim dt As DataTable = New DataTable()
        da.Fill(dt)
        Return dt


    End Function

    Public Shared Sub InsertQuanDAO(ByVal quan As QuanDTO)
        ' Dim sqlcn As SqlDataProvider = New SqlDataProvider()
        Dim cn As SqlConnection
        cn = SqlDataProvider.ConnectionData()
        Dim ds As ArrayList = New ArrayList()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "Insert_Quan"
        cmd.Connection = cn
        cmd.Connection.Open()

        Dim para As SqlParameter = New SqlParameter("TenQuan", SqlDbType.NVarChar, 50)
        para.Direction = ParameterDirection.Input
        para.Value = quan.TenQuan
        cmd.Parameters.Add(para)

        para = New SqlParameter("SoCongTyToiDa", SqlDbType.Int)
        para.Direction = ParameterDirection.Input
        para.Value = quan.SoCongTyToiDaMoiQuan
        cmd.Parameters.Add(para)

        cmd.ExecuteNonQuery()
        cmd.Connection.Close()

    End Sub

    Public Shared Sub UpdateQuanDAO(ByVal quan As QuanDTO)
        ' Dim sqlcn As SqlDataProvider = New SqlDataProvider()
        Dim cn As SqlConnection
        cn = SqlDataProvider.ConnectionData()
        Dim ds As ArrayList = New ArrayList()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "Update_Quan"
        cmd.Connection = cn
        cmd.Connection.Open()

       

        Dim para As SqlParameter = New SqlParameter("TenQuan", SqlDbType.NVarChar, 50)
        para.Direction = ParameterDirection.Input
        para.Value = quan.TenQuan
        cmd.Parameters.Add(para)

        para = New SqlParameter("MaQuan", SqlDbType.Int)
        para.Direction = ParameterDirection.Input
        para.Value = quan.MaQuan
        cmd.Parameters.Add(para)

        para = New SqlParameter("SoCongTyToiDa", SqlDbType.Int)
        para.Direction = ParameterDirection.Input
        para.Value = quan.SoCongTyToiDaMoiQuan
        cmd.Parameters.Add(para)

        cmd.ExecuteNonQuery()
        cmd.Connection.Close()

    End Sub


    Public Shared Sub DeleteQuanDAO(ByVal MaQuan As Integer)
        ' Dim sqlcn As SqlDataProvider = New SqlDataProvider()
        Dim cn As SqlConnection
        cn = SqlDataProvider.ConnectionData()
        Dim ds As ArrayList = New ArrayList()
        Dim cmd As SqlCommand = New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "Delete_Quan"
        cmd.Connection = cn
        cmd.Connection.Open()

        Dim para As SqlParameter = New SqlParameter("MaQuan", SqlDbType.Int)
        para.Direction = ParameterDirection.Input
        para.Value = MaQuan
        cmd.Parameters.Add(para)



        cmd.ExecuteNonQuery()
        cmd.Connection.Close()

    End Sub
    
End Class
